{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Majalan.Base.Processor
-- Copyright   :  (c) Stephen Tetley 2014
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Events and event lists.
-- 
--------------------------------------------------------------------------------

module Majalan.Base.Processor
  ( 

    Processor
  , applyProcessor
  , makeProcessor



  )  where

import Majalan.Base.Internal.Base
import Majalan.Base.Internal.IStmt


-- User ctx?

data Processor = Processor 
    { proc_apply    :: Seconds -> Seconds -> IStmt 
    , proc_sustain  :: Seconds
    }


applyProcessor :: Processor -> TimeSpan -> (TimeSpan,IStmt)
applyProcessor (Processor proc sus) (TimeSpan t0 d) = 
    let tspan = TimeSpan t0 (d+sus) in (tspan, proc t0 (d+sus))

-- | Processor has a rather prosaic type (it processes only 
-- /writer output/), but we don\'t want to to labour the ScoreTree
-- with polymorphism.
--
makeProcessor :: CsOrch inst => inst -> Seconds -> [Value] -> Processor
makeProcessor inst sus  params = 
    Processor { proc_apply = proc, proc_sustain = sus }
  where
    proc ot drn = IStmt { inst_num      = instNumber $ inst
                        , istart        = ot
                        , iduration     = drn
                        , ivalues       = params
                        }
        




